package com.qfjy.controller.example5;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName BlogController
 * @Description TODO
 * @Author guoweixin
 * @Date 2022/11/22
 * @Version 1.0
 */
@Controller
@RequestMapping("blog")
@ResponseBody
public class BlogController {

    @Autowired
    private AmqpTemplate amqpTemplate;

    /**
     * TODO 根据不同的关注博文，收到不同文章信息
     * TODO 博客blog
     */
    @GetMapping("sendBlog")
    public String sendBlog(HttpServletRequest request){
        // routing key
        String flag=request.getParameter("flag");
        // 消息内容（对象）数据传输
        String msg=request.getParameter("msg");

        /**
         * param1:交换机名称
         * param2: 路由KEY
         * param3:数据传输的对象
         */
        amqpTemplate.convertAndSend("blogTopicExchange",flag,msg);

        return "博客发表成功";
    }
}
